package com.iot.apicontrol.service.impl;


import com.dc3.common.exception.AddException;
import com.iot.apicontrol.dto.Dc3ApiControlDto;
import com.iot.apicontrol.mapper.Dc3ApiMapper;
import com.iot.apicontrol.pojo.Dc3ApiControl;
import com.iot.apicontrol.service.Dc3ApiService;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author 咕唧
 * @Date 2022/7/22 11:14
 * @Version 1.0
 */
@Service
public class Dc3ApiServiceImpl implements Dc3ApiService {

    private Dc3ApiMapper dc3ApiMapper;

    @Resource
    public void setDc3ApiMapper(Dc3ApiMapper dc3ApiMapper) {
        this.dc3ApiMapper = dc3ApiMapper;
    }

    @Override
    public void addApi(Dc3ApiControlDto dc3ApiControlDto) {
        Assert.hasText(dc3ApiControlDto.getApi(), () -> {
            throw new AddException("未填写接口内容");
        });
        Dc3ApiControl dc3ApiControl = new Dc3ApiControl();
        dc3ApiControl.setApi(dc3ApiControlDto.getApi());
        dc3ApiControl.setDescription(dc3ApiControlDto.getDescription());
        dc3ApiMapper.addApi(dc3ApiControl);
    }

    @Override
    public List<Dc3ApiControlDto> findAllApi2Dto() {
        return dc3ApiMapper.findAllApi2Dto();
    }

    @Override
    public Long deleteApi(String id) {
        return dc3ApiMapper.deleteApiById(id);
    }
}
